package strategy;

import java.util.Random;
import java.util.Vector;
import strategy.matchers.*;

public class StrategyOpgave
{
	enum Method {Blind, City, Age, Selection};
	
	public static void main(String[] args)
	{
		Vector<Single> allTheSingleLadies = new Vector<Single>();
		Vector<Single> allTheSingleGentlemen = new Vector<Single>();

		Database.generateContent(30, allTheSingleLadies, false);
		Database.generateContent(30, allTheSingleGentlemen, true);
		
                Method type = Method.Blind;
                
                Match trolling = null;
                switch(type) {
                    case Blind:
                        trolling = new BlindMatch(allTheSingleGentlemen, allTheSingleLadies);
                        ((BlindMatch)trolling).runMatch(allTheSingleGentlemen.get(0));
                        break;
                    case Age:
                        trolling = new AgeMatch(allTheSingleGentlemen, allTheSingleLadies);
                        ((AgeMatch)trolling).runMatch(allTheSingleGentlemen.get(0));
                        break;
                    case City:
                        trolling = new CityMatch(allTheSingleGentlemen, allTheSingleLadies);
                        ((CityMatch)trolling).runMatch(allTheSingleGentlemen.get(0));
                        break;
                    case Selection:
                        trolling = new SelectionMatch(allTheSingleGentlemen, allTheSingleLadies);
                        ((SelectionMatch)trolling).runMatch(allTheSingleGentlemen.get(0));
                        break;
                    default:
                        ;
                }
                
                
                 
	}
	/*
	public static Single match(Single subject, Vector<Single> database, Method method, Object argument)
	{
		Random r = new Random();
		
		switch(method)
		{
		case Blind:
			if (database.isEmpty()) return null;
			else return database.elementAt(r.nextInt(database.size()));
			
		case City:
			Vector<Single> rightCity = new Vector<Single>();
			for (Single single : database)
			{
				if (single.getCity().equals(subject.getCity()))
				{
					rightCity.add(single);
				}
			}
			if (rightCity.isEmpty()) return null;
			else return rightCity.elementAt(r.nextInt(rightCity.size()));
			
		case Age:
			Vector<Single> rightAge = new Vector<Single>();
			int maxYounger = ((int[])argument)[0];
			int maxOlder   = ((int[])argument)[1];
			for (Single single : database)
			{
				if (single.getAge() >= subject.getAge() - maxYounger &&
				    single.getAge() <= subject.getAge() + maxOlder    )
				{
					rightAge.add(single);
				}
			}
			if (rightAge.isEmpty()) return null;
			else return rightAge.elementAt(r.nextInt(rightAge.size()));
			
		case Selection:
			Vector<Single> rightCriteria = new Vector<Single>();
			Criterion[] criteria = (Criterion[])argument;
			for (Single single : database)
			{
				boolean include = true;
				for (Criterion criterion : criteria)
				{
					if (!criterion.applies(single))
					{
						include = false;
						break;
					}
				}
				if (include) rightCriteria.add(single);
			}
			if (rightCriteria.isEmpty()) return null;
			else return rightCriteria.elementAt(r.nextInt(rightCriteria.size()));
			
		default:
			return null;
		}
	}*/
}